import os
import cv2

# 遍历目录下所有文件
file_suffix = ['.jpg', '.png', '.jpeg']
for root, dirs, files in os.walk("./choose_imgs"):
    for file in files:
        if os.path.splitext(file)[1] in file_suffix:
            file_path = os.path.join(root, file)
            img = cv2.imread(file_path)
            # 获取旋转矩阵
            M = cv2.getRotationMatrix2D((img.shape[1] / 2, img.shape[0] / 2), 45, 0.7)
            # 旋转图片
            rotated_img = cv2.warpAffine(img, M, (img.shape[1], img.shape[0]), borderMode=cv2.BORDER_CONSTANT, borderValue=(255, 255, 255))
            # cv2.imshow("rotated_img", rotated_img)
            # cv2.waitKey(0)
            if not os.path.exists("./save_img"):
                os.mkdir("./save_img")
            file_path = os.path.join("./save_img", file)
            cv2.imwrite(file_path, rotated_img)
